package com.rtline.business.handler;

import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;

import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;

/**
 * <p>CustomHorizontalCellStyleStrategy .
 *
 * <p>change history:
 *
 * <pre>
 * date         defect       person          comments
 * --------------------------------------------------------------------------------
 * 2025/6/20    ********     Tao Ren    create file.
 * </pre>
 *
 * @author Tao Ren
 * @date 2025/6/20 11:08
 */
public class CustomHorizontalCellStyleStrategy extends HorizontalCellStyleStrategy {
    public CustomHorizontalCellStyleStrategy() {
        super(createHeadStyle(), createContentStyle());
    }

    private static WriteCellStyle createHeadStyle() {
        WriteCellStyle headStyle = new WriteCellStyle();
        WriteFont headFont = new WriteFont();
        headFont.setBold(true); // 设置字体加粗
        headFont.setFontHeightInPoints((short) 12); // 设置字体大小
        headStyle.setWriteFont(headFont);

        headStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex()); // 设置背景颜色
        headStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND); // 设置填充模式
        headStyle.setBorderTop(BorderStyle.THIN); // 设置上边框
        headStyle.setBorderBottom(BorderStyle.THIN); // 设置下边框
        headStyle.setBorderLeft(BorderStyle.THIN); // 设置左边框
        headStyle.setBorderRight(BorderStyle.THIN); // 设置右边框
        headStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); // 设置水平居中
        headStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 设置垂直居中
        return headStyle;
    }

    private static WriteCellStyle createContentStyle() {
        WriteCellStyle contentStyle = new WriteCellStyle();
        WriteFont contentFont = new WriteFont();
        contentFont.setFontHeightInPoints((short) 11); // 设置字体大小
        contentStyle.setWriteFont(contentFont);

        contentStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex()); // 设置背景颜色
        contentStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND); // 设置填充模式
        contentStyle.setBorderTop(BorderStyle.THIN); // 设置上边框
        contentStyle.setBorderBottom(BorderStyle.THIN); // 设置下边框
        contentStyle.setBorderLeft(BorderStyle.THIN); // 设置左边框
        contentStyle.setBorderRight(BorderStyle.THIN); // 设置右边框
        contentStyle.setHorizontalAlignment(HorizontalAlignment.LEFT); // 设置水平左对齐
        contentStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 设置垂直居中
        return contentStyle;
    }
}
